package patterns.chain;

/**
 * Created by lenovo on 2016/11/29 0029.
 * 演示，调用不同级别的日志
 */
public class ChainPatternDemo {
    private static AbstractLogger getChainOfLogger() {
        AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
        AbstractLogger fileLogger = new FileLogger(AbstractLogger.FILE);
        AbstractLogger infoLogger = new InfoLogger(AbstractLogger.INFO);
        //设置责任链，可以调用比自己更细化的logger对象
        errorLogger.setNextLogger(fileLogger);
        fileLogger.setNextLogger(infoLogger);

        return errorLogger;
    }

    public static void main(String[] args) {
        AbstractLogger loggerChain = getChainOfLogger();

        loggerChain.logMsg(AbstractLogger.INFO, "Just an information.");
        loggerChain.logMsg(AbstractLogger.FILE, "This is an file level information.");
        loggerChain.logMsg(AbstractLogger.ERROR, "Oh ! my god this is an error .");
    }
}
